<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="./lib/react.js"></script>
    <script src="./lib/react_dom.js"></script>
    <script src="./lib/babel.js"></script>

    <script type="text/babel">
      class App extends React.Component {
        constructor() {
          super()
          this.state = {
            message: 'hello world',

            isReady: true,

            friend: {
              name: 'kobe',
              desc: '凌晨4点钟的太阳',
            },
          }
        }

        render() {
          const { message, isReady, friend } = this.state

          // 1.条件判断
          let showElement = null
          if (isReady) {
            showElement = <div>开始</div>
          } else {
            showElement = <div>准备</div>
          }

          return (
            <div>
              {/* 1.条件判断 */}
              <div>{showElement}</div>

              {/* 2.三元运算符 */}
              <div>{isReady ? '开始' : '准备'}</div>

              {/* 3.&& */}
              <div>{friend && <div>{friend.name}</div>}</div>
            </div>
          )
        }
      }

      const root = ReactDOM.createRoot(document.querySelector('#root'))
      root.render(<App />)
    </script>
  </body>
</html>
